package cn.arnold.offer.xiaohs;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class Soultion {


    class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;
    }

    public class Solution {
        /**
         * @param node TreeNode类
         * @return int整型ArrayList<ArrayList <>>
         */
        public ArrayList<ArrayList<Integer>> printNode(TreeNode node) {
            ArrayList<ArrayList<Integer>> ret = new ArrayList<>();
            if (node == null) {
                return ret;
            }
            Queue<TreeNode> queue = new LinkedList<>();
            queue.offer(node);
            while (!queue.isEmpty()) {
                ArrayList<Integer> level = new ArrayList<>();
                int currentLevelSize = queue.size();
                for (int i = 1; i <= currentLevelSize; i++) {
                    TreeNode nodeTemp = queue.poll();
                    level.add(nodeTemp.val);
                    if (node.left != null) {
                        queue.offer(nodeTemp.left);
                    }
                    if (node.right != null) {
                        queue.offer(nodeTemp.right);
                    }
                }
                ret.add(level);
            }
            return ret;
        }
    }
}
